import { defHttp } from '@/utils/http/axios';
import { GetPluginListParams, PluginModel, PluginSourceAppModel, InstallPluginParams, UninstallPluginParams } from './model/plugin';

import { ErrorMessageMode } from '#/axios';

export function setPluginSourceApp(params: PluginSourceAppModel, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: `/plugin/plugins/set-source-app`,
      params
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function getPluginSourceApp(mode: ErrorMessageMode = 'message') {
  return defHttp.get<PluginSourceAppModel>(
    {
      url: `/plugin/plugins/source-app`,
    },
    {
      errorMessageMode: mode,
    }
  );
}

export function getPluginList(params: GetPluginListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<PluginModel>(
    {
      url: '/plugin/plugins',
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}

export function installPlugin(params: InstallPluginParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: '/plugin/plugins/install',
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

export function uninstallPlugin(params: UninstallPluginParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: '/plugin/plugins/uninstall',
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}